Strict
Private

#If LANG="cpp" Then
Import externs_cpp
#Else
#Error "MonkeyLua is not currently supported for this language."
#End

#REFLECTION_FILTER=""

Import reflection

''''''''''''''''''' EXTERNS '''''''''''''''''''

Public Extern
' Externed struct wrappers
Class Pointer="ml_Pointer"
	Method Equals:Bool(other:Pointer)
End
Class lua_Alloc="ml_lua_Alloc"
End
Class lua_State="ml_lua_State"
	Method Equals:Bool(other:lua_State)
End
Class luaL_Buffer="ml_luaL_Buffer"
End

Private Extern
' Externed callback function
Class ml_MonkeyFunction
Private
	Method ml_Func:Int(state:lua_State)
End

' All wrapped externs are methods in the ml_MonkeyLua class so that they may be called from externed code
Class ml_MonkeyLua
	Method ml_lua_call:Void(L:lua_State, nargs:Int, nresults:Int)
	Method ml_lua_checkstack:Int(L:lua_State, extra:Int)
	Method ml_lua_close:Void(L:lua_State)
	Method ml_lua_concat:Void(L:lua_State, n:Int)
	' cpcall
	Method ml_lua_createtable:Void(L:lua_State, narr:Int, nrec:Int)
	' dump
	Method ml_lua_equal:Int(L:lua_State, index1:Int, index2:Int)
	Method ml_lua_error:Int(L:lua_State)
	Method ml_lua_gc:Int(L:lua_State, what:Int, data:Int)
	Method ml_lua_getallocf:lua_Alloc(L:lua_State, ud:Pointer)
	Method ml_lua_getallocf_rv:lua_Alloc(L:lua_State, ud:Pointer, rv:lua_Alloc)
	Method ml_lua_getfenv:Void(L:lua_State, index:Int)
	Method ml_lua_getfield:Void(L:lua_State, index:Int, k:String)
	Method ml_lua_getglobal:Void(L:lua_State, name:String)
	' gethook
	' gethookcount
	' gethookmask
	' getinfo
	' getlocal
	Method ml_lua_getmetatable:Int(L:lua_State, index:Int)
	' getstack
	Method ml_lua_gettable:Void(L:lua_State, index:Int)
	Method ml_lua_gettop:Int(L:lua_State)
	Method ml_lua_getupvalue:String(L:lua_State, funcindex:Int, n:Int)
	Method ml_lua_insert:Void(L:lua_State, index:Int)
	Method ml_lua_isboolean:Int(L:lua_State, index:Int)
	Method ml_lua_iscfunction:Int(L:lua_State, index:Int)
	Method ml_lua_isfunction:Int(L:lua_State, index:Int)
	Method ml_lua_islightuserdata:Int(L:lua_State, index:Int)
	Method ml_lua_isnil:Int(L:lua_State, index:Int)
	Method ml_lua_isnone:Int(L:lua_State, index:Int)
	Method ml_lua_isnoneornil:Int(L:lua_State, index:Int)
	Method ml_lua_isnumber:Int(L:lua_State, index:Int)
	Method ml_lua_isstring:Int(L:lua_State, index:Int)
	Method ml_lua_istable:Int(L:lua_State, index:Int)
	Method ml_lua_isthread:Int(L:lua_State, index:Int)
	Method ml_lua_isuserdata:Int(L:lua_State, index:Int)
	Method ml_lua_lessthan:Int(L:lua_State, index1:Int, index2:Int)
	' load
	Method ml_lua_newstate:lua_State(f:lua_Alloc, ud:Pointer=NULL_PTR)
	Method ml_lua_newstate_rv:lua_State(f:lua_Alloc, ud:Pointer=NULL_PTR, rv:lua_State)
	Method ml_lua_newtable:Void(L:lua_State)
	Method ml_lua_newthread:lua_State(L:lua_State)
	Method ml_lua_newthread_rv:lua_State(L:lua_State, rv:lua_State)
	Method ml_lua_newuserdata:Pointer(L:lua_State, size:Int)
	Method ml_lua_newuserdata_rv:Pointer(L:lua_State, size:Int, rv:Pointer)
	Method ml_lua_next:Int(L:lua_State, index:Int)
	Method ml_lua_objlen:Int(L:lua_State, index:Int)
	Method ml_lua_pcall:Int(L:lua_State, nargs:Int, nresults:Int, msgh:Int)
	Method ml_lua_pop:Void(L:lua_State, n:Int)
	Method ml_lua_pushboolean:Void(L:lua_State, b:Int)
	' pushcclosure
	' pushcfunction
	' pushfstring
	Method ml_lua_pushinteger:Void(L:lua_State, n:Int)
	Method ml_lua_pushlightuserdata:Void(L:lua_State, p:Pointer)
	Method ml_lua_pushliteral:String(L:lua_State, s:String)
	Method ml_lua_pushlstring:Void(L:lua_State, s:String, len:Int)
	Method ml_lua_pushnil:Void(L:lua_State)
	Method ml_lua_pushnumber:Void(L:lua_State, n:Float)
	Method ml_lua_pushstring:Void(L:lua_State, s:String)
	Method ml_lua_pushthread:Int(L:lua_State)
	Method ml_lua_pushvalue:Void(L:lua_State, index:Int)
	' pushvfstring
	Method ml_lua_rawequal:Int(L:lua_State, index1:Int, index2:Int)
	Method ml_lua_rawget:Void(L:lua_State, index:Int)
	Method ml_lua_rawgeti:Void(L:lua_State, index:Int, n:Int)
	Method ml_lua_rawset:Void(L:lua_State, index:Int)
	Method ml_lua_rawseti:Void(L:lua_State, index:Int, n:Int)
	' register
	Method ml_lua_remove:Void(L:lua_State, index:Int)
	Method ml_lua_replace:Void(L:lua_State, index:Int)
	Method ml_lua_resume:Int(L:lua_State, narg:Int)
	Method ml_lua_setallocf:Void(L:lua_State, f:lua_Alloc, ud:Pointer)
	Method ml_lua_setfenv:Int(L:lua_State, index:Int)
	Method ml_lua_setfield:Void(L:lua_State, index:Int, k:String)
	Method ml_lua_setglobal:Void(L:lua_State, name:String)
	' sethook
	' setlocal
	Method ml_lua_setmetatable:Void(L:lua_State, index:Int)
	Method ml_lua_settable:Void(L:lua_State, index:Int)
	Method ml_lua_settop:Void(L:lua_State, n:Int)
	Method ml_lua_setupvalue:String(L:lua_State, funcindex:Int, n:Int)
	Method ml_lua_status:Int(L:lua_State)
	Method ml_lua_toboolean:Int(L:lua_State, index:Int)
	' tocfunction
	Method ml_lua_tointeger:Int(L:lua_State, index:Int)
	' tolstring
	Method ml_lua_tonumber:Float(L:lua_State, index:Int)
	Method ml_lua_topointer:Pointer(L:lua_State, index:Int)
	Method ml_lua_tostring:String(L:lua_State, index:Int)
	Method ml_lua_tothread:lua_State(L:lua_State, index:Int)
	Method ml_lua_tothread_rv:lua_State(L:lua_State, index:Int, rv:lua_State)
	Method ml_lua_type:Int(L:lua_State, index:Int)
	Method ml_lua_typename:String(L:lua_State, tp:Int)
	Method ml_lua_xmove:Void(stfrom:lua_State, stto:lua_State, n:Int)
	Method ml_lua_yield:Int(L:lua_State, nresults:Int)
	
' luaL externs
	Method ml_luaL_addchar:Void(B:luaL_Buffer, c:Int)
	Method ml_luaL_addlstring:Void(B:luaL_Buffer, s:String, l:Int)
	Method ml_luaL_addsize:Void(B:luaL_Buffer, n:Int)
	Method ml_luaL_addstring:Void(B:luaL_Buffer, s:String)
	Method ml_luaL_addvalue:Void(B:luaL_Buffer)
	Method ml_luaL_argcheck:Void(L:lua_State, cond:Int, narg:Int, extramsg:String)
	Method ml_luaL_argerror:Int(L:lua_State, narg:Int, extramsg:String)
	Method ml_luaL_buffinit:Void(L:lua_State, B:luaL_Buffer)
	Method ml_luaL_callmeta:Int(L:lua_State, obj:Int, e:String)
	Method ml_luaL_checkany:Void(L:lua_State, narg:Int)
	Method ml_luaL_checkint:Int(L:lua_State, narg:Int)
	Method ml_luaL_checkinteger:Int(L:lua_State, narg:Int)
	Method ml_luaL_checklong:Int(L:lua_State, narg:Int)
	' checklstring
	Method ml_luaL_checknumber:Float(L:lua_State, narg:Int)
	' checkoption
	Method ml_luaL_checkstack:Void(L:lua_State, sz:Int, msg:String)
	Method ml_luaL_checkstring:String(L:lua_State, narg:Int)
	Method ml_luaL_checktype:Void(L:lua_State, narg:Int, t:Int)
	Method ml_luaL_checkudata:Pointer(L:lua_State, narg:Int, tname:String)
	Method ml_luaL_dofile:Int(L:lua_State, filename:String)
	Method ml_luaL_dostring:Int(L:lua_State, str:String)
	Method ml_luaL_error:Int(L:lua_State, argcount%, fmt$, arg1$, arg2$, arg3$, arg4$, arg5$, arg6$, arg7$, arg8$, arg9$, arg10$)
	Method ml_luaL_getmetafield:Int(L:lua_State, obj:Int, e:String)
	Method ml_luaL_getmetatable:Void(L:lua_State, tname:String)
	Method ml_luaL_gsub:String(L:lua_State, s:String, p:String, r:String)
	Method ml_luaL_loadbuffer:Int(L:lua_State, buff:Int[], sz:Int, name:String)
	Method ml_luaL_loadfile:Int(L:lua_State, filename:String)
	Method ml_luaL_loadstring:Int(L:lua_State, s:String)
	Method ml_luaL_newmetatable:Int(L:lua_State, tname:String)
	Method ml_luaL_newstate:lua_State()
	Method ml_luaL_newstate_rv:lua_State(rv:lua_State)
	Method ml_luaL_openlibs:Void(L:lua_State)
	Method ml_luaL_optint:Int(L:lua_State, narg:Int, d:Int)
	Method ml_luaL_optinteger:Int(L:lua_State, narg:Int, d:Int)
	Method ml_luaL_optlong:Int(L:lua_State, narg:Int, d:Int)
	' optlstring
	Method ml_luaL_optnumber:Float(L:lua_State, narg:Int, d:Float)
	Method ml_luaL_optstring:String(L:lua_State, narg:Int, d:String)
	' prepbuffer
	' pushresult
	Method ml_luaL_ref:Int(L:lua_State, t:Int)
	' register
	Method ml_luaL_typename:String(L:lua_State, index:Int)
	Method ml_luaL_typerror:Int(L:lua_State, narg:Int, tname:String)
	Method ml_luaL_unref:Void(L:lua_State, t:Int, ref:Int)
	Method ml_luaL_where:Void(L:lua_State, lvl:Int)
	
	Method ml_SetMLI:Void(obj:Object)
	Method ml_Init:Void(L:lua_State)
	
	Method ml_IsMonkeyObject:Bool(L:lua_State, idx:Int)
	Method ml_PushMonkeyObject:Void(L:lua_State, obj:Object)
	Method ml_PushMonkeyFunction:Void(L:lua_State, func:ml_MonkeyFunction)
	Method ml_ToMonkeyObject:Object(L:lua_State, idx:Int)
	Method ml_ToMonkeyFunction:ml_MonkeyFunction(L:lua_State, idx:Int)

	' Virtual
	Method ml_GetField:Int(L:lua_State)
	Method ml_SetField:Int(L:lua_State)
	Method ml_Retain:Void(obj:Object)
	Method ml_Release:Void(obj:Object)
End
